//
//  WYEditProductController.m
//  Boss
//
//  Created by admin on 2018/7/18.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYEditProductController.h"
#import "WYAddProductController.h"
@interface WYEditProductController ()
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topHeight;
@property (strong, nonatomic) IBOutlet UIImageView *productImageView;
@property (strong, nonatomic) IBOutlet UITextField *titleTextField;
@property (strong, nonatomic) IBOutlet UITextField *introductionTextField;
@end

@implementation WYEditProductController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    // Do any additional setup after loading the view from its nib.
}
-(void)setupUI
{
    self.topHeight.constant = self.navHeight;
    self.navigationItem.title = @"产品服务";
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithTitle:@"编辑" style:(UIBarButtonItemStyleDone) target:self action:@selector(editProductAction)];
    
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithTitle:@"删除" style:(UIBarButtonItemStyleDone) target:self action:@selector(deleteProductAction)];
    self.navigationItem.rightBarButtonItems = @[item1,item2];
    
//    [self.productImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@!default",_service.picUrl]] placeholderImage:[UIImage imageNamed:@""]];
    self.productImageView.image = self.image;
    self.titleTextField.text = self.service.title;
    self.introductionTextField.text = self.service.content;
    self.titleTextField.userInteractionEnabled = NO;
    self.introductionTextField.userInteractionEnabled = NO;
    [self.productImageView setContentMode:(UIViewContentModeScaleAspectFill)];
    self.productImageView.clipsToBounds = YES;
}
-(void)editProductAction
{
    WYAddProductController *avc = [[WYAddProductController alloc]init];
    avc.service  = self.service;
    avc.image = self.image;
    avc.isEdit = YES;
    [self.navigationController pushViewController:avc animated:YES];
}
-(void)deleteProductAction
{
    WEAKSELF
    [WYHttpServer deleteProductServiceWithID:self.service.id SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
     
        if (success) {
        //    [weakSelf toast:@"删除成功"];
            [weakSelf.navigationController popViewControllerAnimated: YES];
        }else{
            [weakSelf toast:errorMessage];
        }
    }];
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
